package ccmis.material.facility.action;

import java.util.ArrayList;
import java.util.List;

import jfox.platform.infrastructure.SuperAction;
import jfox.platform.sample.SampleAction.ExampleEntity;
import org.jfox.framework.annotation.Service;
import org.jfox.mvc.ActionContext;
import org.jfox.mvc.PageContext;
import org.jfox.mvc.annotation.ActionMethod;


/**
 * 
 * @author <a href="mailto:thaiguo@gmail.com">Taiguo Zhang</a>
 *
 */
@Service(id = "facilityinventory")
public class InventoryAction extends SuperAction {
	
	@ActionMethod(name = "mgmt", successView = "ccmis/material/facility/inventory_management.vhtml")
	public void managementView(ActionContext actionContext)throws Exception{
		List<ExampleEntity> exampleTreeNodes = new ArrayList<ExampleEntity>();

        int rootNodeCounts = 0;
        while (rootNodeCounts < 1) {
            rootNodeCounts = (int)(Math.random() * 10);
        }
        for (int count = 0; count < rootNodeCounts; count++) {
            ExampleEntity root = new ExampleEntity();
            root.setName("TREE_NODE_" + root.getId());
            exampleTreeNodes.add(root);

            int childCounts = 0;
            while (childCounts < 1) {
                childCounts = (int)(Math.random() * 10);
            }
            for (int c = 0; c < childCounts; c++) {
                ExampleEntity child = new ExampleEntity();
                child.setName("TREE_NODE_" + child.getId());
                child.setParentId(root.getId());
                exampleTreeNodes.add(child);
                //Thread.sleep(10);
            }
        }

        PageContext pageContext = actionContext.getPageContext();
        pageContext.setAttribute("exampleTreeNodes", exampleTreeNodes);
	}

}
